package com.xbongbong.pro.enums;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.WorkReportDailyEnum;
import com.xbongbong.saas.enums.business.WorkReportFieldEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author 吴峰
 * @version v1.0
 * @date 2019/1/24 14:55
 * @since v1.0
 */
@Getter
public enum WorkReportEnum {

    /**
     * 工作报告
     */
    WORKREPORT_DAILY("enum.workReport.name.workreport_daily",  XbbRefTypeEnum.WORKREPORT_DAILY.getAlias(), XbbRefTypeEnum.WORKREPORT_DAILY.getCode()),
    WORKREPORT_WEEKLY("enum.workReport.name.workreport_weekly", XbbRefTypeEnum.WORKREPORT_WEEKLY.getAlias(), XbbRefTypeEnum.WORKREPORT_WEEKLY.getCode()),
    WORKREPORT_MONTHLY("enum.workReport.name.workreport_monthly", XbbRefTypeEnum.WORKREPORT_MONTHLY.getAlias(), XbbRefTypeEnum.WORKREPORT_MONTHLY.getCode()),
    ;

    /**
     * saas应用标示解释
     */
    private String name;
    /**
     * saas应用标示
     */
    private String alias;

    private Integer code;

    WorkReportEnum(String name, String alias, Integer code) {
        this.name = name;
        this.alias = alias;
        this.code = code;
    }

    public static WorkReportEnum getByCode(Integer code) {
        for(WorkReportEnum workReportEnum: values()) {
            if(workReportEnum.getCode().equals(code)) {
                return workReportEnum;
            }
        }
        return null;
    }

    public static List<WorkReportEnum> getList() {
        return new ArrayList<>(Arrays.asList(values()));
    }

    /**
     * app端详情默认标题显示字段
     *
     * @author GuoJun.HU
     * @since V1.0
     * @return List
     * @date 2019/4/8 19:21
     */
    public static List<Object> getTitleAttrList() {
        JSONObject titleType = new JSONObject();
        titleType.put("attr", WorkReportFieldEnum.TYPE.getAttr());
        titleType.put("attrName", WorkReportDailyEnum.TYPE.getAttrName());

        JSONObject timeType = new JSONObject();
        titleType.put("attr", WorkReportFieldEnum.REPORT_DATE.getAttr());
        titleType.put("attrName", WorkReportDailyEnum.REPORT_DATE.getAttrName());

        return Arrays.asList(titleType, timeType);
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    public String getI18nName() {
        return name;
    }

    public static String getI18nValue(String value) {
        return I18nMessageUtil.getMessage(value);
    }
}
